﻿using System;
using System.IO;
using System.Reflection;

namespace SB.Logging
{
    public static class LoggingFacade
    {
        private static bool initialized = false;

        public static void Initialize()
        {
            Stream configStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SB.Logging.Log4Net.Log4Net.config");
            Initialize(configStream);
        }

        public static void Initialize(Assembly assembly, string configResourceName)
        {
            Stream configStream = assembly.GetManifestResourceStream(configResourceName);
            Initialize(configStream);
        }

        public static void Initialize(Stream configStream)
        {
            log4net.Config.XmlConfigurator.Configure(configStream);
            configStream.Close();
            initialized = true;
        }

        public static ILogger GetLogger(Type owner)
        {
            if(!initialized)
                Initialize();

            return new Log4NetLogger(owner);
        }
    }
}
